<%--
  Created by IntelliJ IDEA.
  User: feng
  Date: 2023/5/11
  Time: 12:48
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>体育馆管理系统</title>
    <meta name="description" content="体育馆管理系统">
    <meta name="keywords" content="体育馆管理系统">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="<%=request.getContextPath()%>/resources/plugins/elementui/index.css">
    <link rel="stylesheet" href="<%=request.getContextPath()%>/resources/plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="<%=request.getContextPath()%>/resources/css/style.css">
    <!-- 引入组件库 -->
    <script type="text/javascript" src="<%=request.getContextPath()%>/resources/js/jquery.min.js"></script>
    <script src="<%=request.getContextPath()%>/resources/js/vue.js"></script>
    <script src="<%=request.getContextPath()%>/resources/plugins/elementui/index.js"></script>
    <script src="<%=request.getContextPath()%>/resources/js/axios-0.18.0.js"></script>
    <style>
        .datatable {
            position: relative;
            box-sizing: border-box;
            -webkit-box-flex: 1;
            width: 100%;
            max-width: 100%;
            font-size: 14px;
            color: rgb(96, 98, 102);
            overflow: hidden;
            flex: 1 1 0%;
        }
        .datatable td, .datatable th {
            padding: 12px 0;
            min-width: 0;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            text-overflow: ellipsis;
            vertical-align: middle;
            position: relative;
            text-align: left;
        }
    </style>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>场地管理<small>场地管理</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>预约管理</el-breadcrumb-item>
            <el-breadcrumb-item>场地管理</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <el-input placeholder="编码/名称/助记码" v-model="pagination.queryString" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter"></el-input>
                <el-button @click="findPage()" class="dalfBut">查询</el-button>
                <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
            </div>
            <el-table size="small" current-row-key="placeNo" :data="dataList" stripe highlight-current-row>
                <el-table-column type="index" align="center" label="序号"></el-table-column>
                <el-table-column prop="placeNo" label="场地编码" align="center"></el-table-column>
                <el-table-column prop="placeName" label="场地名" align="center"></el-table-column>
                <el-table-column prop="placeAddress" label="场地详细位置" align="center"></el-table-column>
                <el-table-column prop="placeRemark" label="说明" align="center"></el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">修改</el-button>
                        <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.pageNow"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>
            <!-- 新增标签弹层 -->
            <div class="add-form">
                <el-dialog title="新增场地" :visible.sync="dialogFormVisible">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="基本信息" name="first">
                                <el-form label-position="right" label-width="100px">
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="场地名">
                                                <el-input v-model="formData.placeName"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="场地负责人">
                                                <el-input v-model="formData.staffID"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="负责人电话">
                                                <el-input v-model="formData.placePrincipal"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="租借费用（元/次）">
                                                <el-input v-model="formData.placeCost"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="24">
                                            <el-form-item label="场地详细位置">
                                                <el-input v-model="formData.placeAddress" type="textarea"></el-input>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="24">
                                            <el-form-item label="场地备注">
                                                <el-input v-model="formData.placeRemark" type="textarea"></el-input>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>

                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">确定</el-button>
                    </div>
                </el-dialog>
            </div>

            <!-- 编辑标签弹层 -->
            <div class="add-form">
                <el-dialog title="编辑场地" :visible.sync="dialogFormVisible4Edit">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="基本信息" name="first">
                                <el-form label-position="right" label-width="100px">
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="场地名">
                                                <el-input v-model="formData.placeName"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="场地负责人">
                                                <el-input v-model="formData.staffID"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="负责人电话">
                                                <el-input v-model="formData.placePrincipal"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="租借费用（元/次）">
                                                <el-input v-model="formData.placeCost"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="24">
                                            <el-form-item label="场地详细位置">
                                                <el-input v-model="formData.placeAddress" type="textarea"></el-input>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="24">
                                            <el-form-item label="场地备注">
                                                <el-input v-model="formData.placeRemark" type="textarea"></el-input>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                        <el-button type="primary" @click="handleChange()">确定</el-button>
                    </div>
                </el-dialog>
            </div>
        </div>
    </div>
</div>
</body>

<script>
    var vue = new Vue({
        el: '#app',
        data:{
            activeName:'first',//添加/编辑窗口Tab标签名称
            pagination: {//分页相关属性
                pageNow: 1,
                pageSize:10,
                total:100,
                queryString:null,
            },
            dataList: [],//列表数据
            formData: {},//表单数据
            tableData:[],//新增和编辑表单中对应的检查项列表数据
            checkitemIds:[],//新增和编辑表单中检查项对应的复选框，基于双向绑定可以进行回显和数据提交
            dialogFormVisible: false,//控制添加窗口显示/隐藏
            dialogFormVisible4Edit:false//控制编辑窗口显示/隐藏
        },
        created() {
            this.findPage();
        },
        methods: {
            //编辑
            handleChange() {
                this.$confirm('是否确定修该场地信息?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    //发送ajax请求，提交模型数据
                    axios.post("<%=request.getContextPath()%>/site/change.do",this.formData).then((response)=> {
                        //隐藏编辑窗口
                        this.dialogFormVisible4Edit = false;
                        if(response.data.success){
                            this.$message({
                                message: response.data.data,
                                type: 'success'
                            });
                        }else{
                            this.$message.error(response.data.data);
                        }
                    }).finally(()=> {
                        this.findPage();
                    });
                }).catch(() => {
                    // 点击取消进行的操作
                })

            },
            //添加
            handleAdd () {
                //发送ajax请求将模型数据提交到后台处理
                this.$confirm('是否确定添加该场地?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.formData.placeState = "0";
                    axios.post("<%=request.getContextPath()%>/site/add.do",this.formData)
                        .then((response)=> {
                            //关闭新增窗口
                            this.dialogFormVisible = false;
                            if(response.data.success){
                                //新增成功，弹出成功提示
                                this.$message({
                                    message: response.data.data,
                                    type: 'success'
                                });
                            }else{
                                //新增失败，弹出错误提示
                                this.$message.error(response.data.data);
                            }
                        }).finally(()=> {
                        this.findPage();
                    });
                }).catch(() => {
                    // 点击取消进行的操作
                })

            },
            //分页查询
            findPage() {
                //分页参数
                var param = {
                    pageNow:this.pagination.pageNow,//页码
                    pageSize:this.pagination.pageSize,//每页显示的记录数
                    placeNo:this.pagination.queryString,//查询条件
                    placeName:this.pagination.queryString//查询条件
                };
                //请求后台
                axios.post("<%=request.getContextPath()%>/site/find.do",param).then((response)=> {
                    //为模型数据赋值，基于VUE的双向绑定展示到页面
                    this.dataList = response.data.data.rows;
                    this.pagination.total =  response.data.data["totalCount"];
                });
            },
            // 重置表单
            resetForm() {
                this.formData = {};
            },
            // 弹出添加窗口
            handleCreate() {
                this.resetForm();
                this.dialogFormVisible = true;
                //默认切换到第一个标签页（基本信息）
                this.activeName='first';
                //重置
                this.checkitemIds = [];
            },
            // 弹出编辑窗口
            handleUpdate(row) {
                var param = {
                    placeNo:row["placeNo"]//查询条件
                };
                axios.post("<%=request.getContextPath()%>/site/find.do",param).then((res)=>{
                    if(res.data.data.rows.length === 1){
                        //弹出编辑窗口
                        this.dialogFormVisible4Edit = true;
                        //为模型数据赋值，通过VUE数据双向绑定进行信息的回显
                        this.formData={};
                        console.log(res.data.data.rows[0]);
                        this.formData = res.data.data.rows[0];
                    }else{
                        this.$message.error("获取数据失败，请刷新当前页面");
                    }
                });
            },
            //切换页码
            handleCurrentChange(pageNow) {
                //pageNow为切换后的页码
                this.pagination.pageNow = pageNow;
                this.findPage();
            },
            // 删除
            handleDelete(row) {
                //发送ajax请求将模型数据提交到后台处理
                this.$confirm('是否确定删除该场地?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    var param = {
                        placeNo:row["placeNo"]
                    };
                    axios.post("<%=request.getContextPath()%>/site/delete.do",param).then((res)=>{
                        if(res){
                            this.$message({
                                message: res.data.data,
                                type: 'success'
                            });
                        }else{
                            this.$message.error("删除失败");
                        }
                    }).finally(()=> {
                        this.findPage();
                    });
                }).catch(() => {
                    // 点击取消进行的操作
                })

            }
        }
    })
</script>
</html>

